package main

import (
	"fmt"
	"strings"
)

func wordPattern(pattern string, s string) bool {
	mapP2S, mapS2P := map[byte]string{}, map[string]byte{}
	sList := strings.Split(s, " ")
	if len(pattern) != len(sList) {
		return false
	}
	for i := range pattern {
		pB, sS := pattern[i], sList[i]
		if mapP2S[pB] == "" {
			mapP2S[pB] = sS
		}
		if mapS2P[sS] == 0 {
			mapS2P[sS] = pB
		}
		if mapP2S[pB] != sS || mapS2P[sS] != pB {
			return false
		}
	}
	return true
}

func main() {
	fmt.Println(wordPattern("abba", "dog cat cat dog"))
}
